package org.afk.tools.io;

import org.afk.tools.log.*;

/**
 * Created by IntelliJ IDEA.
 * User: axel
 * Date: 06.12.11
 * Time: 11:09
 * To change this template use File | Settings | File Templates.
 */
public class SpamThread extends Thread
{
	private final ErrorHandler errorHandler;
	private final Object printable;
	private final int sleepTime;
	private boolean stop;

	public SpamThread(final int sleepTime, final Object printable, final ErrorHandler errorHandler)
	{
		this.sleepTime = sleepTime;
		this.printable = printable;
		this.errorHandler = errorHandler;
	}

	public void pleaseStop()
	{
		this.stop = true;
		this.interrupt();
	}

	@Override
	public void run()
	{
		for (;;)
			try
			{
				if (this.stop)
					break;
				Thread.sleep(this.sleepTime);
				this.errorHandler.info("" + this.printable);
			}
			catch (final InterruptedException e)
			{
				break;
			}
	}
}
